var express = require('express');
var router = express.Router();
const JwtUtil = require('../models/jwt');
var verify = require('../models/verify')
var jsonParser = express.json()
var urlencodedParser = express.urlencoded({ extended: false })

/* GET users listing. */
router.get('/',verify, function (req, res, next) {
  const user = {
    code:200,
    errorCode:200,
    avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
    introduction: "我是超级管理员",
    name: "Super Admin",
    roles: ["admin"],
    menuList: [{
      path: '/sys',
      component: 'layout/Layout',
      name: 'sys',
      meta: {title: 'sys', icon: 'dashboard'},
      list: [{
        path: 'config',
        name: 'config',
        component: 'sys/config/index',
        meta: {title: 'config', noCache: true},
      }, {
        path: 'menu',
        name: 'menu',
        component: 'sys/menu/index',
        meta: {title: 'menu', noCache: true}
      }, {
        path: 'role',
        name: 'role',
        component: 'sys/role/index',
        meta: {title: 'role'},
      }, {
        path: 'user',
        name: 'user',
        component: 'sys/user/index',
        meta: {title: 'user'}
      }]
    }
    ]
  }
  res.send(user);
});
router.post('/login',urlencodedParser, function (req, res) {
  // let body = JSON.parse(req.body)
  if (req.body.username == 'admin' && req.body.password == '1111111') {
    let jwt = new JwtUtil({username: 'admin', password: '1111111'});//数据库查出来的用户id
    let token = jwt.generateToken(); // 生成token
    console.log(token)
    res.send({code: 200, errorCode: 200, errorMsg: '', message: '登录成功', token: token});
  }
  else {
    res.send({code: 200, errorCode: 500, errorMsg: '用户名或密码错误', message: '登录失败'});
  }
})
router.get('/logout', function (req, res) {
  res.send({
    status: 1,
    success: '退出成功'
  })
})
module.exports = router;
